package com.wk.code.wkserver.controller.admin;


import com.wk.code.wkserver.controller.common.BaseController;
import com.wk.code.wkserver.response.admin.MenuResponse;
import com.wk.code.wkserver.response.admin.PermissionResponse;
import com.wk.code.wkserver.response.admin.PermissionTreeResponse;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.request.admin.PermissionRequest;
import com.wk.code.wkserver.service.IPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 权限控制层
 *
 * @author wq
 * @date 2021-07-12 14:42:10
 */
@RestController
@AllArgsConstructor
@Api(tags = "admin-系统菜单管理")
@RequestMapping("admin/menus")
public class AdminPermissionController extends BaseController {

    private final IPermissionService permissionService;


    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    @PostMapping("add")
    public R<?> add(@RequestBody PermissionRequest req) {
        permissionService.addPermission(req);
        return R.success();
    }

    @ApiOperation(value = "更新菜单", notes = "更新菜单")
    @PostMapping("update/{id}")
    public R<?> update(@PathVariable Integer id, PermissionRequest req) {
        permissionService.updatePermission(id, req);
        return R.success();
    }


    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    @PostMapping("del/{id}")
    public R<?> del(@PathVariable Integer id) {
        permissionService.delPermission(id);
        return R.success();
    }


    @ApiOperation(value = "树形菜单", notes = "树形菜单")
    @PostMapping("tree")
    public R<?> tree() {
        List<PermissionTreeResponse> tree = permissionService.findTree();
        return R.success(tree);
    }

    @ApiOperation(value = "获取菜单列表", notes = "获取菜单列表")
    @GetMapping("/getMenus")
    public R<List<MenuResponse>> getMenus() {
        return R.success(permissionService.getMenus(getSysUserId()));
    }


    @ApiOperation(value = "详情菜单", notes = "详情菜单")
    @GetMapping("detail")
    public R<?> detail(Integer id) {
        PermissionResponse detail = permissionService.detail(id);
        return R.success(detail);
    }
}
